|
1
|
|
|
var assert = require('chai').assert, |
|
2
|
|
|
GedcomX = require('../'); |
|
3
|
|
|
|
|
4
|
|
|
describe('Date', function(){ |
|
5
|
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
|
7
|
|
|
var newGDate = new GedcomX.Date(), |
|
8
|
|
|
date = GedcomX.Date(); |
|
9
|
|
|
assert.instanceOf(newGDate, GedcomX.Date, 'An instance of GedcomX.Date is not returned when calling the constructor with new.'); |
|
10
|
|
|
assert.instanceOf(date, GedcomX.Date, 'An instance of GedcomX.Date is not returned when calling the constructor without new.'); |
|
11
|
|
|
}); |
|
12
|
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
|
14
|
|
|
var date = GedcomX.Date({ |
|
15
|
|
|
id: 'date', |
|
16
|
|
|
original: 'June 24 1899', |
|
17
|
|
|
formal: '+1899-06-24' |
|
18
|
|
|
}); |
|
19
|
|
|
assert.equal(date.getId(), 'date'); |
|
20
|
|
|
assert.equal(date.getOriginal(), 'June 24 1899'); |
|
21
|
|
|
assert.equal(date.getFormal(), '+1899-06-24'); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
it('Build', function(){ |
|
25
|
|
|
var date = GedcomX.Date() |
|
26
|
|
|
.setId('date') |
|
27
|
|
|
.setOriginal('June 24 1899') |
|
28
|
|
|
.setFormal('+1899-06-24'); |
|
29
|
|
|
assert.equal(date.getId(), 'date'); |
|
30
|
|
|
assert.equal(date.getOriginal(), 'June 24 1899'); |
|
31
|
|
|
assert.equal(date.getFormal(), '+1899-06-24'); |
|
32
|
|
|
}); |
|
33
|
|
|
|
|
34
|
|
|
it('toJSON', function(){ |
|
35
|
|
|
var data = { |
|
36
|
|
|
id: 'date', |
|
37
|
|
|
original: 'June 24 1899', |
|
38
|
|
|
formal: '+1899-06-24' |
|
39
|
|
|
}, date = GedcomX.Date(data); |
|
40
|
|
|
assert.deepEqual(date.toJSON(), data); |
|
41
|
|
|
}); |
|
42
|
|
|
|
|
43
|
|
|
it('constructor does not copy instances', function(){ |
|
44
|
|
|
var obj1 = GedcomX.Date(); |
|
45
|
|
|
var obj2 = GedcomX.Date(obj1); |
|
46
|
|
|
assert.strictEqual(obj1, obj2); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
}); |